﻿using Python.Runtime;
using System;

string pathToVirtualEnv = @"C:\software\python\install";
Runtime.PythonDLL = pathToVirtualEnv+ "\\python313.dll";
string pythonHome = pathToVirtualEnv + "\\python.exe";
PythonEngine.PythonHome = pythonHome;

PythonEngine.PythonPath = $"{pathToVirtualEnv}\\Lib\\site-packages;{pathToVirtualEnv}\\Lib;C:\\code\abp\\dotnetpython\\dotnetpythonDemo\\py\\";

PythonEngine.Initialize();
using (Py.GIL())
{   // TestDemo为TestDemo.py文件，在放在D:\\tempCode\\ 目录
    dynamic np = Py.Import("setup");
    double r = np.func(9, 27);
    Console.WriteLine($"计算结果{r}");//计算结果为6
}
////也可以直接搞用第三方库numpy里面的方法
//using (Py.GIL())
//{
//    dynamic np = Py.Import("numpy");
//    double r = np.sqrt(64);
//    Console.WriteLine($"计算结果{r}");//计算结果为8
//}
